package com.zecan.blog.job;

import com.zecan.blog.dao.ClassifyMapper;
import com.zecan.blog.dao.TagMapper;
import com.zecan.blog.utils.SpringUtils;
import com.zecan.blog.utils.StringUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 更新数据库中分类表和标签表数量
 * @ClassName UpdateArticleCountJob
 * @Description
 * @date 2022/11/17 20:34
 * @Version 1.0
 */
@Component
public class UpdateClassifyTagCountJob extends QuartzJobBean {

    private ClassifyMapper classifyMapper = SpringUtils.getBean(ClassifyMapper.class);

    private TagMapper tagMapper = SpringUtils.getBean(TagMapper.class);

    public static final Integer[] TAG_IDS = {1,2,3,4,5,6,7,8};

    public static   final Integer[] CLASSIFY_IDS = {1,2,3,4,5,6,7,8};

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        System.out.println("当前时间:" + StringUtils.dateFormat(new Date()) + "更新分类标签数量定时任务开始执行");

        classifyMapper.updateClassifyCount(CLASSIFY_IDS);
        tagMapper.updateTagCount(TAG_IDS);

        System.out.println("当前时间:" + StringUtils.dateFormat(new Date()) + "更新分类标签数量定时任务执行结束");

    }
}
